<script>
	var rmaCreationMode = <?php echo ($this->isCreationMode()? 'true':'false'); ?>;
	var reservationUrl = '<?php echo $this->getUrl('ProductReturn/Admin/ReserveProduct', array('rma_id' => $this->getRma()->getId())); ?>';
	
	//translations
	<?php echo $this->addJsTranslation('Please select at least on product'); ?>
	<?php echo $this->addJsTranslation('Please select destination for products to process'); ?>
	<?php echo $this->addJsTranslation('Please confirm products processing'); ?>
</script>

<input type="hidden" id="data[rma_id]" name="data[rma_id]" value="<?php echo $this->getRma()->getId(); ?>">
<input type="hidden" id="data[rma_order_id]" name="data[rma_order_id]" value="<?php echo $this->getRma()->getSalesOrder()->getId(); ?>">
<input type="hidden" id="data[rma_customer_id]" name="data[rma_customer_id]" value="<?php echo $this->getRma()->getrma_customer_id(); ?>">
<input name="form_key" type="hidden" value="<?php echo $this->getFormKey() ?>" />
<div class="entry-edit">
    
	    <div class="entry-edit-head"> 
		    <h4 class="icon-head head-edit-form fieldset-legend">General</h4> 
	    </div>
        <fieldset id="my-fieldset">
            <table cellspacing="0" class="form-list">
                <tr>
                    <td class="label"><?php echo $this->__('Reference'); ?></td>
                    <td class="input-ele"><input type="text" name="data[rma_ref]" id="data[rma_ref]" value="<?php echo $this->getRma()->getrma_ref(); ?>"></td>
                    <td width="100">&nbsp;</td>
                    <td class="label"><?php echo $this->__('Status'); ?></td>
                    <td class="input-ele"><?php echo $this->getStatusesAsCombo('data[rma_status]', $this->getRma()->getrma_status()); ?></td>                    
                </tr>
                <tr>
                    <td class="label"><?php echo $this->__('Created At'); ?></td>
                    <td class="input-ele"><?php echo $this->formatDate($this->getRma()->getrma_created_at(), 'medium'); ?></td>
                    <td width="100">&nbsp;</td>
                </tr>
                <tr>
                    <td class="label"><?php echo $this->__('Updated At'); ?></td>
                    <td class="input-ele"><?php echo $this->formatDate($this->getRma()->getrma_updated_at(), 'medium'); ?></td>
                    <td width="100">&nbsp;</td>
                    <td class="label"><?php echo $this->__('Valid until'); ?></td>
                    <td class="input-ele">
                       	<input size="9" type="text" id="data[rma_expire_date]" name="data[rma_expire_date]" value="<?php echo $this->getRma()->getrma_expire_date(); ?>">
                    	<img src="<?php echo $this->getSkinUrl('images/grid-cal.gif') ?>" class="v-middle" id="img_calendar_date" />
				        <script type="text/javascript">
			                Calendar.setup({
			                    inputField : 'data[rma_expire_date]',
			                    ifFormat : '%Y-%m-%e',
			                    button : 'img_calendar_date',
			                    align : 'Bl',
			                    singleClick : true
			                });
		                </script>	
                    </td>
                </tr>
                <tr>
                    <td class="label"><?php echo $this->__('Customer'); ?></td>
                    <?php if($this->getRma()->IamGuest()) : ?>
                    	<td class="input-ele"><?php echo $this->getRma()->getCustomer()->getName().' '.$this->__('( Guest )'); ?></td>
                    <?php else : ?>
                    	<td class="input-ele"><a href="<?php echo $this->getCustomerUrl(); ?>"><?php echo $this->getRma()->getCustomer()->getName(); ?></a></td>
                    <?php endif; ?>
                    <td width="100">&nbsp;</td>
                    <td class="label"><?php echo $this->__('Products Reception Date'); ?></td>
                    <td class="input-ele">
                       	<input size="9" type="text" id="data[rma_reception_date]" name="data[rma_reception_date]" value="<?php echo $this->getRma()->getrma_reception_date(); ?>">
                    	<img src="<?php echo $this->getSkinUrl('images/grid-cal.gif') ?>" class="v-middle" id="img_calendar_rma_reception_date" />
				        <script type="text/javascript">
			                Calendar.setup({
			                    inputField : $('data[rma_reception_date]'),
			                    ifFormat : '%Y-%m-%e',
			                    button : $('img_calendar_rma_reception_date'),
			                    align : 'Bl',
			                    singleClick : true
			                });
		                </script>	

                    </td>
                </tr>
                <tr>
                    <td class="label"><?php echo $this->__('Sales Order'); ?></td>
                    <td class="input-ele"><a href="<?php echo $this->getSalesOrderUrl(); ?>"><?php echo $this->getRma()->getSalesOrder()->getincrement_id(); ?></a></td>
                    <td width="100">&nbsp;</td>
                    <td class="label"><?php echo $this->__('Products Return Date'); ?></td>
                    <td class="input-ele">
                       	<input size="9" type="text" id="data[rma_return_date]" name="data[rma_return_date]" value="<?php echo $this->getRma()->getrma_return_date(); ?>">
                    	<img src="<?php echo $this->getSkinUrl('images/grid-cal.gif') ?>" class="v-middle" id="img_calendar_rma_return_date" />
				        <script type="text/javascript">
			                Calendar.setup({
			                    inputField : $('data[rma_return_date]'),
			                    ifFormat : '%Y-%m-%e',
			                    button : $('img_calendar_rma_return_date'),
			                    align : 'Bl',
			                    singleClick : true
			                });
		                </script>	
                    </td>
                </tr>
                <tr>
                    <td class="label"><?php echo $this->__('Customer Phone'); ?></td>
                    <td class="input-ele"><input type="text" name="data[rma_customer_phone]" id="data[rma_customer_phone]" value="<?php echo $this->getRma()->getrma_customer_phone(); ?>"></td>
                </tr>
                <tr>
                    <td class="label"><?php echo $this->__('Customer Email'); ?></td>
                    <td class="input-ele">
                    	<input type="text" name="data[rma_customer_email]" id="data[rma_customer_email]" value="<?php echo $this->getRma()->getrma_customer_email(); ?>">
                    	<img src="<?php echo $this->getSkinUrl('ProductReturn/mail.png'); ?>" onclick="mailToCustomer();">
                    </td>
                </tr>
                <tr>
                    <td class="label"><?php echo $this->__('Customer Address'); ?></td>
                    <td class="input-ele" colspan="4"><?php echo $this->getCustomerAddressesAsCombo('data[rma_address_id]', $this->getRma()->getrma_address_id()); ?></td>
                </tr>
           </table>
        </fieldset>
  	    <div class="entry-edit-head"> 
		    <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Products'); ?></h4> 
	    </div>
        <fieldset id="my-fieldset">
        	<div class="grid"> 
				<table cellspacing="0" class="form-list" style="width:100%;">
					<thead> 
		                <tr class="headings"> 
	    	            	<th><span class="nobr"><?php echo $this->__('Product'); ?></span></th> 
	    	            	<th><span class="nobr"><?php echo $this->__('Available Qty'); ?></span></th> 
	    	            	<th><span class="nobr"><?php echo $this->__('Qty to return'); ?></span></th> 
	    	            	<th><span class="nobr"><?php echo $this->__('Reason'); ?></span></th> 
	    	            	<th><span class="nobr"><?php echo $this->__('Comments'); ?></span></th> 
	    	            	<th><span class="nobr"><?php echo $this->__('Serials'); ?></span></th> 
	    	            </tr>
	    	        </thead>
	    	        <tbody>
	    	        		<?php foreach($this->getRma()->getProducts() as $product): ?>
	    	        			<?php if($this->displayProduct($product)): ?>
				    	        	<tr>
			    	        			<td><a href="<?php echo $this->getProductUrl($product); ?>"><?php echo $this->getProductName($product); ?></a></td>
			    	        			<td class="a-center"><?php echo $this->getAvailableQty($product); ?></td>
			    	        			<?php if ($this->hasBeenProcessed($product) == ''): ?>
				    	        			<td class="a-center"><input type="text" size="4" name="data[rp_qty_<?php echo $product->getitem_id(); ?>]" id="data[rp_qty_<?php echo $product->getitem_id(); ?>]" value="<?php echo (int)$product->getrp_qty(); ?>"></td>
				    	        		<?php else: ?>
				    	        			<td class="a-center"><?php echo (int)$product->getrp_qty(); ?></td>
				    	        		<?php endif; ?>
				    	        		<td class="a-center"><?php echo $this->getProductReasonCombo('data[rp_reason_'.$product->getitem_id().']', $product->getrp_reason()); ?></td>
			    	        			<td class="a-center"><textarea cols="40" rows="2" name="data[rp_description_<?php echo $product->getitem_id(); ?>]" id="data[rp_description_<?php echo $product->getitem_id(); ?>]"><?php echo $product->getrp_description(); ?></textarea></td>
			    	        			<td class="a-center"><textarea cols="40" rows="2" name="data[rp_serials_<?php echo $product->getitem_id(); ?>]" id="data[rp_serials_<?php echo $product->getitem_id(); ?>]"><?php echo $product->getrp_serials(); ?></textarea></td>
				    	        	</tr>
			    	        	<?php  endif; ?>
		   	        		<?php endforeach; ?>
	    	        </tbody>
				</table>
			</div>
		</fieldset>
  	    <div class="entry-edit-head"> 
		    <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $this->__('Comments'); ?></h4> 
	    </div>
        <fieldset id="my-fieldset">
			<table cellspacing="0" class="form-list">
                <tr>
                    <td class="label"><?php echo $this->__('Private comments'); ?></td>
                    <td class="input-ele"><textarea cols="90" rows="5" name="data[rma_private_description]" id="data[rma_private_description]"><?php echo $this->getRma()->getrma_private_description(); ?></textarea></td>
                </tr>
                <tr>
                    <td class="label"><?php echo $this->__('Public Comments'); ?></td>
                    <td class="input-ele"><textarea cols="90" rows="5" name="data[rma_public_description]" id="data[rma_public_description]"><?php echo $this->getRma()->getrma_public_description(); ?></textarea></td>
                </tr>
           </table>
        </fieldset>
</div>